package com.inspur.gs.sbssdl.sbwhgl.sbwhby.sbwhby.front.ebyearsearch.voactions;
import com.inspur.edp.bff.api.manager.context.QueryContext;
import com.inspur.edp.bff.spi.action.query.AbstractQueryAction;
import com.inspur.edp.caf.db.dbaccess.DynamicResultRow;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.qdp.bql.api.IBqlExecuter;
import io.iec.edp.caf.runtime.config.BqlBeanUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

public class ebyearSearchVOAction extends AbstractQueryAction {

	public ebyearSearchVOAction(QueryContext context){
		super(context);
	}


	public static final String yearsql = "SELECT DISTINCT sbejbyfk.year FROM sbejbyfk.sbejbyfk";

	private final IBqlExecuter bqlExecuter = BqlBeanUtil.getAppCtx().getBean(IBqlExecuter.class);
	@Override
	public void execute() {

		ArrayList<String> beIds = new ArrayList<>();
		beIds.add("cde823e0-7159-4c28-b411-165d30abfe4c");

		List<DynamicResultRow> rows = bqlExecuter.executeSelectStatement(yearsql, beIds);


		ArrayList<IEntityData> entityData=new ArrayList<>();
		for(DynamicResultRow resultRow:rows){
			IEntityData voEntityData =getContext().createData();
			String uuid = UUID.randomUUID().toString();
			voEntityData.setValue("ID",uuid);
			if(resultRow.getValues().get(0) != null)
				voEntityData.setValue("year",resultRow.getValues().get(0).toString());
			entityData.add(voEntityData);
		}
		HashMap<String,ArrayList<IEntityData>> queryResult = new HashMap<String,ArrayList<IEntityData>>();
		queryResult.put("queryresult",entityData);
		setResult(queryResult);
	}
}
